# _*_ coding : utf-8 _*_
# @Time : 2023/12/5 21:51
# @Author : 韩宗森
# @File : 13_微博的cookie登录
# @Project : pythonProject


# 适用的场景:数据采集的时候需要绕过登陆然后进入到某个页面
# 个人信息页面是utf-8但是还报错了编码错误︰因为并没有进入到个人信息页面而是跳转到了登陆页面
# 那么登陆页面不是utf-8所以报错
# 什么情况下访问不成功?

# 因为请求头的信息不够所以访问不成功

import urllib.request

url = 'https://user.qzone.qq.com/502982971'

"""
# 微博的
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
    'Cookie': 'XSRF-TOKEN=ZOOx-xNIXY8sCVQsDe-xF_dz; SUB=_2AkMSM6Qif8NxqwFRmfoXyWrla41-yQHEieKkb1X5JRMxHRl-yT9kqmY4tRB6ObOKzVph6J0szZYJrYyp5YO_Ws8II_rG; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WhvlIVg5Ip01M0FXLHPf7s_; WBPSESS=V0zdZ7jH8_6F0CA8c_ussRLAurvQS-wASK9eg75HUicAYoHi0E1MPuAZu-6kwt2-1lXCFhakUnIxuLCtKqFPSr4JoM4Z3sSo-QCPQvbGK7YjiZVLI9pbuKb807AKh_huLSwynOL8q4KdwfuO5G-IpOg6eYZ5OIM58kvp9N7D43U=; PC_TOKEN=5d0af77ed3; login_sid_t=e57de4c23900ddd5e1e097e3726d17ed; cross_origin_proto=SSL; WBStorage=4d96c54e|undefined; _s_tentry=weibo.com; Apache=7826971203195.63.1701784355026; SINAGLOBAL=7826971203195.63.1701784355026; ULV=1701784355028:1:1:1:7826971203195.63.1701784355026:; wb_view_log=2048*11521.25',
    # referer判断当前路径是不是由上一个路径进来的 一般情况下是做图片防盗辫
    'referer': 'https://weibo.com/'
}
"""
# QQ空间的
headers = {
    'Cookie': 'RK=9B/lVTZIMC; ptcz=380bd8633d2572b7ef608386aa298db9534f55ac4ffed2af0348fb0dcaf3a711; ETCI=8e49819525f34831bc9ab630947bbe08; pgv_pvid=1296694172; fqm_pvqid=cbf5b0fb-0271-4ad8-82d1-c99ea8408acd; zzpaneluin=; zzpanelkey=; _qpsvr_localtk=0.9200804721665639; pgv_info=ssid=s5007780120; uin=o0502982971; skey=@HzUqABjq7; p_uin=o0502982971; pt4_token=OAa5F9JmlSNeLG51kFHI6kIC3PgeAGY925kGAwvtvH8_; p_skey=b7eZbECQdGu-kPOzG9SGN*NG75-rVrZdIYMM5qTMae4_; Loading=Yes; qz_screen=2048x1152; QZ_FE_WEBP_SUPPORT=1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
}
# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)

# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)

# 获取响应的内容
content = response.read().decode('utf-8')

# 数据下载到本地
with open('qq空间.html', 'w', encoding='utf-8') as fp:
    fp.write(content)
